* regressions_informal_idom_bite_mensual.do	JEP	01/25/15
* Does regressions that are in the term paper, for informal workers: RIF11
* Include domestic workers
* Monthly wage

*************************** Change log ********************************** 

/*
	01/26/15	Add confirmation of .ster files to avoid reruns
*/	

clear 
version 13.1

* Project info
cap project, doinfo
if _rc==198 {
	loc master "/home/jperez/AA_Minimum_Wage" 
 loc pr = 0
}
else {
	local master "`r(pdir)'"
	local doname "`r(dofile)'"  
 loc pr = 1
	* Project calls
	project, uses("`master'/Data/Source/ocupados_mw.dta")
	* Call programs
	project, relies_on("`master'/Code/Est/sample_choice.do")
	project, relies_on("`master'/Code/Est/build_mw_measures.do")
	project, relies_on("`master'/Code/Est/build_treatment.do")
	project, relies_on("`master'/Code/Est/export_rif.do")
	project, relies_on("`master'/Code/Est/confirmedrun.do")
	project, relies_on("`master'/Code/Est/graph_rif.do")
}
*/


* Call necessary programs. I do not call using project to carry the programs around. I do not put these in the ado/personal folder because they are specific to the project. They are not ado files.
do "`master'/Code/Est/sample_choice.do"
do "`master'/Code/Est/build_mw_measures.do"
do "`master'/Code/Est/build_treatment.do"
do "`master'/Code/Est/export_rif.do"
do "`master'/Code/Est/confirmedrun.do"
do "`master'/Code/Est/graph_rif.do"

use "`master'/Data/Source/ocupados_mw.dta", clear

* Choose quantiles
glo qtiles "5 10 15 20 25 30 50 75 90"
* Number of bootstraps
glo boot=10

* RIF 4 - Tables numbered 4 in term paper

* Choose sample
mysample rif11sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) informal domestic exind(13,29,42)
tab rif11sample
tab tipo_trabajador if rif11sample
tab year if rif11sample
tab horas_semana if rif11sample 
tab sex if rif11sample
tab afiliado_salud if rif11sample
* Build mw measures
mw_measures rif11sample , stub(rif11)
* Build treatment
mytreatment, posts("tq(1999q1)") mw(bite_rif11) wage(salario_mensual_real)

* RIF regressions

* Create estimation results folder if it doesn't already exist
cap mkdir "`master'/Ster/rif11_new"


foreach x in $qtiles {
	di " Percentile `x'"
	loc fw: word 1 of $qtiles
	loc count: word count $qtiles
	di `count'
	loc lw: word `count' of $qtiles
	if `x'==`lw' & `pr'!=0 loc reg="register"
	else loc reg ""
	if `x'==`fw' loc r="replace"
	else loc r="append"
	
	* Panel A. Employment
	confirmedrun, `reg' controls() name(`master'/Ster/rif11_new/reg_emp_tq(1999q1)_bite_salario_mensual_real_50_idom) rif(rif11A) p(`x') r(`r') sample(rif11sample) rerun
	* cgmrif2 lw treat i.ccode i.time emp if rif11sample , hyp(0) boot($boot) cluster(ccode) x(treat) i(ccode) t(time) q(`x') rif(rif11A`x')
	* exportrif, name(`master'/Ster/rif11_new/reg_emp_tq(1999q1)_bite_salario_mensual_real_50_idom) p(`x') r(`r')
	* Panel B. Employment and Bartik Price Variable
	confirmedrun, `reg' controls(bartikp1) name(`master'/Ster/rif11_new/reg_emp_bp_tq(1999q1)_bite_salario_mensual_real_50_idom) rif(rif11B) p(`x') r(`r') sample(rif11sample) rerun
	* Panel C. Employment and Bartik Quantity Variable
	confirmedrun, `reg' controls(bartikq) name(`master'/Ster/rif11_new/reg_emp_bq_tq(1999q1)_bite_salario_mensual_real_50_idom) rif(rif11C) p(`x') r(`r') sample(rif11sample) rerun
	* Panel D. Employment and City Trends
	confirmedrun, `reg' controls(i.ccode#c.trend) name(`master'/Ster/rif11_new/reg_sst_emp_tq(1999q1)_bite_salario_mensual_real_50_idom) rif(rif11D) p(`x') r(`r') sample(rif11sample) rerun
	* Panel E. Employment, Bartik Price Variable and City Trends
	confirmedrun, `reg' controls(i.ccode#c.trend bartikp1) name(`master'/Ster/rif11_new/reg_sst_emp_bp_tq(1999q1)_bite_salario_mensual_real_50_idom) rif(rif11E) p(`x') r(`r') sample(rif11sample) rerun
	* Panel F. Employment, Bartik Quantity Variable and City Trends
	confirmedrun, `reg' controls(i.ccode#c.trend bartikq) name(`master'/Ster/rif11_new/reg_sst_emp_bq_tq(1999q1)_bite_salario_mensual_real_50_idom) rif(rif11F) p(`x') r(`r') sample(rif11sample) rerun
	
}


* Graph results and export

clear

cap program drop mex
program define mex
	cap mkdir "`2'/Doc/ster_figures/rif11_new"
	cap mkdir "`2'/Doc/ster_figures/rif11_new/1999q1"
	graph export "`2'/Doc/ster_figures/rif11_new/1999q1/`1'.eps", replace
	! epstopdf "`2'/Doc/ster_figures/rif11_new/1999q1/`1'.eps"
	erase "`2'/Doc/ster_figures/rif11_new/1999q1/`1'.eps"
	* project, creates("`master'/Doc/descriptive_figures/density/`1'.pdf")
end	

foreach spec in reg_emp reg_emp_bp reg_emp_bq reg_sst_emp_bp reg_sst_emp_bq {
	graph drop _all
	graphrif, master("`master'") ster(Ster) folder(rif11_new) qtiles($qtiles) spec(`spec') time(tq(1999q1)) rareaopts(bcolor(gs13))twowayopts(title("Informal sector - Bite" "`spec' - 1999q1" ) xtitle(Percentile) ytitle(Coef) /* yscale(range(-0.0075 0.0075)) ylabel(-0.0075(0.0025)0.0075) */ yline(0))
	mex `spec' "`master'"
}


